package com.cb.oss.controller;

import com.cb.oss.service.OssService;
import com.cb.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author cb
 * @version 1.0
 * @date 2020/6/22 12:17
 */
@Api(description = "ali-oss-文件管理")

@RestController
@RequestMapping("/ossservice/fileoss")
public class OssController {

    private final OssService ossService;

    @Autowired
    public OssController(OssService ossService) {
        this.ossService = ossService;
    }

    @ApiOperation("上传文件")
    @PostMapping
    public R uploadOssFile(MultipartFile file){
        // return 文件上传后的路径
        String url = ossService.uploadFileAvatar(file);

        return R.ok().data("url",url);
    }
}
